package com.zhihuichongcheng.application.ui.approval.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.smartlib.cmnObject.util.DateUtil;
import com.smartlib.cmnObject.util.DeviceUtil;
import com.zhihuichongcheng.application.R;
import com.zhihuichongcheng.application.bean.approval.Tasks;
import com.zhihuichongcheng.application.bean.mine.UserBean;
import com.zhihuichongcheng.application.glide.GlideCircleTransform;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by 3water on 2016/11/14.
 */

public class ApprovalCommentAdapter extends RecyclerView.Adapter<ApprovalCommentAdapter.ViewHold> {
    private Context mContext;
    private List<Tasks> mListData = new ArrayList<>();
    public ApprovalCommentAdapter(Context context)
    {
        this.mContext = context;
    }
    @Override
    public ViewHold onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.listadapter_cricle_comment,null);
        return new ViewHold(view);
    }

    @Override
    public void onBindViewHolder(ViewHold holder, int position) {
        Tasks tasks = mListData.get(position);
        UserBean userBean = tasks.getUser();
        if(userBean!=null)
        {
            Glide.with(mContext).load(userBean.getLogoUrl()).asBitmap().placeholder(R.drawable.ic_default_avatar).
                    transform(new GlideCircleTransform(mContext)).into(holder.mImAvatar);
            holder.mTvName.setText(userBean.getUserName());
        }
        Date date = DateUtil.parseStringToDate(tasks.getCreateTime(),"yyyy年MM月dd日 HH:mm:ss");
        holder.mTvTime.setText(DateUtil.format(date));
        holder.mTvCommentContent.setText(tasks.getRemark());
        if(position == mListData.size()-1)
        {
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)holder.mViewBottom.getLayoutParams();
            params.setMargins(DeviceUtil.dip2px(mContext,0),0,0,0);
            holder.mViewBottom.setLayoutParams(params);
        }
        else
        {
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)holder.mViewBottom.getLayoutParams();
            params.setMargins(DeviceUtil.dip2px(mContext,60),0,0,0);
            holder.mViewBottom.setLayoutParams(params);
        }
    }

    @Override
    public int getItemCount() {
        return mListData.size();
    }

    public void setData(List<Tasks> list) {
        this.mListData = list;
    }

    class ViewHold extends RecyclerView.ViewHolder
    {
        private ImageView mImAvatar;
        private TextView mTvName,mTvCommentContent,mTvTime;
        private View mViewBottom;
        public ViewHold(View itemView) {
            super(itemView);
            mImAvatar = (ImageView)itemView.findViewById(R.id.im_avatar);
            mTvName = (TextView)itemView.findViewById(R.id.tv_name);
            mTvTime = (TextView)itemView.findViewById(R.id.tv_time);
            mTvCommentContent = (TextView)itemView.findViewById(R.id.tv_content);
            mViewBottom = (View)itemView.findViewById(R.id.view_bottom);
        }
    }


}
